{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "demodulationClassify.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "db38IBBCqEot",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#!/usr/bin/python\n",
        "# coding = utf-8\n",
        "\n",
        "import numpy as np\n",
        "from keras import metrics, regularizers, backend\n",
        "from keras.utils import np_utils\n",
        "from keras.models import Model\n",
        "from keras.layers import Input, Dense\n",
        "from keras.callbacks import EarlyStopping, ModelCheckpoint\n",
        "import numpy as np\n",
        "import tensorflow as tf\n",
        "import random as rn\n",
        "import os\n",
        "import json\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "from keras import metrics, regularizers, optimizers, backend\n",
        "from keras.callbacks import TensorBoard, EarlyStopping\n",
        "from keras.models import Model\n",
        "from keras.layers import Input, Dense, Dropout, BatchNormalization, Conv2D, Flatten, pooling\n",
        "from keras.utils import np_utils, vis_utils\n",
        "from keras import metrics, regularizers, optimizers, backend\n",
        "from keras.callbacks import TensorBoard, EarlyStopping\n",
        "from keras.models import Model\n",
        "from keras.layers import Input, Dense, LSTM, CuDNNLSTM, Flatten, Dropout, BatchNormalization\n",
        "from keras.utils import np_utils, vis_utils\n",
        "\n",
        "from keras.layers import Input, Dense, LSTM, CuDNNLSTM, CuDNNGRU, SimpleRNN, Flatten, Dropout, BatchNormalization\n",
        "import scipy.io as sio\n",
        "\n",
        "\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6Yp8iAkxsQcH",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "seqLen = 100\n",
        "#QPSK 四个相位\n",
        "nClass = 4\n",
        "samNum = 1000 * nClass\n",
        "x_data_mat = sio.loadmat('train_demodulation_data_psk4.mat')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GUzO4uUKupmP",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "print(y_data_mat_int[0])\n",
        "type(y_data_mat_int[0])"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "i3PaFA9AzlGu",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "print(a)\n",
        "b=y_data_mat_int[0]\n",
        "b=np.array(b)\n",
        "print(b)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nx1R-LVr0aqM",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "np_utils.to_categorical(b,nClass)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "niVpRQPyu1-E",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "x_data_complex = x_data_mat['signalData_psk4']\n",
        "x_data_real = x_data_complex.real\n",
        "x_data_imag = x_data_complex.imag\n",
        "#x_data_real = x_data_real.reshape((1000,100))\n",
        "#x_data_imag = x_data_imag.reshape((1000,100))\n",
        "x_train = np.stack((x_data_real, x_data_imag), axis=2)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3PLNI0gBOXkT",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "88338e5a-4a96-4737-c774-9a21919cf3e1"
      },
      "source": [
        "x_train.shape"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(1000, 100, 2)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LjvxMuHBvt2P",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "y_data_mat = sio.loadmat('train_demodulation_label_psk4.mat')\n",
        "y_data_mat_int  = y_data_mat['labelData_psk4']\n",
        "\n",
        "y_train = np_utils.to_categorical(y_data_mat_int, nClass)\n",
        "#y_train = y_train.reshape(1000,100,5)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YVmtQGig3MYI",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "print(y_train)\n",
        "print(x_train)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "uUVmbfsO32dM",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#分割训练集和验证集\n",
        "    xTrain = x_train[0:int(x_train.shape[0]*9/10),:]\n",
        "    yTrain = y_train[0:int(y_train.shape[0]*9/10),:]\n",
        "    #此为验证集\n",
        "    xVal = x_train[int(x_train.shape[0]*9/10):-1,:]\n",
        "    yVal = y_train[int(y_train.shape[0]*9/10):-1,:]"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "bTc35B7a3SIc",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "9dc44319-0009-4bf9-934e-1550fcef4977"
      },
      "source": [
        " \n",
        "    \n",
        "    # train model\n",
        "    _in_ = Input(shape = (xTrain.shape[1], xTrain.shape[2]))\n",
        "    ot = Dense(1024,activation='relu')(_in_)\n",
        "    #ot = Dense(256,use_bias=True, activation='relu')(ot)\n",
        "    ot = Dense(500,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(64,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(32,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(16,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(8,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(10,use_bias=True, activation='relu')(ot)\n",
        "    _out_ = Dense(nClass, activation='softmax')(ot)\n",
        "    model = Model(_in_, _out_)\n",
        "\n",
        "\n",
        "    #early_stopping = EarlyStopping(monitor='val_loss', patience=10)\n",
        "    checkpoint = ModelCheckpoint(filepath='weights', monitor='val_loss', verbose=1, save_best_only=False)\n",
        "    adam = optimizers.Adam(lr=0.01, beta_1=0.9, beta_2=0.999, epsilon=1e-08)\n",
        "    model.compile(loss='categorical_crossentropy',\n",
        "                   optimizer=adam,\n",
        "                   metrics=['categorical_accuracy'])\n",
        "\n",
        "\n",
        "    model.fit(xTrain, yTrain, \n",
        "              epochs=100, \n",
        "              batch_size=250,\n",
        "              validation_data=(xVal,yVal),\n",
        "              shuffle = True,\n",
        "              verbose = 2,\n",
        "              callbacks = [checkpoint])\n",
        "    print(\"evaluate the model - train_set:\")\n",
        "    model.summary()"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Train on 900 samples, validate on 99 samples\n",
            "Epoch 1/100\n",
            " - 6s - loss: 0.7631 - categorical_accuracy: 0.6579 - val_loss: 0.4504 - val_categorical_accuracy: 0.8406\n",
            "\n",
            "Epoch 00001: saving model to weights\n",
            "Epoch 2/100\n",
            " - 6s - loss: 0.5021 - categorical_accuracy: 0.8106 - val_loss: 0.4222 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00002: saving model to weights\n",
            "Epoch 3/100\n",
            " - 6s - loss: 0.4847 - categorical_accuracy: 0.8104 - val_loss: 0.3969 - val_categorical_accuracy: 0.8431\n",
            "\n",
            "Epoch 00003: saving model to weights\n",
            "Epoch 4/100\n",
            " - 6s - loss: 0.4778 - categorical_accuracy: 0.8112 - val_loss: 0.3951 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00004: saving model to weights\n",
            "Epoch 5/100\n",
            " - 6s - loss: 0.4684 - categorical_accuracy: 0.8107 - val_loss: 0.3991 - val_categorical_accuracy: 0.8405\n",
            "\n",
            "Epoch 00005: saving model to weights\n",
            "Epoch 6/100\n",
            " - 6s - loss: 0.4709 - categorical_accuracy: 0.8103 - val_loss: 0.3924 - val_categorical_accuracy: 0.8416\n",
            "\n",
            "Epoch 00006: saving model to weights\n",
            "Epoch 7/100\n",
            " - 6s - loss: 0.4674 - categorical_accuracy: 0.8110 - val_loss: 0.3923 - val_categorical_accuracy: 0.8423\n",
            "\n",
            "Epoch 00007: saving model to weights\n",
            "Epoch 8/100\n",
            " - 6s - loss: 0.4668 - categorical_accuracy: 0.8109 - val_loss: 0.3928 - val_categorical_accuracy: 0.8419\n",
            "\n",
            "Epoch 00008: saving model to weights\n",
            "Epoch 9/100\n",
            " - 6s - loss: 0.4672 - categorical_accuracy: 0.8104 - val_loss: 0.3922 - val_categorical_accuracy: 0.8420\n",
            "\n",
            "Epoch 00009: saving model to weights\n",
            "Epoch 10/100\n",
            " - 6s - loss: 0.4657 - categorical_accuracy: 0.8108 - val_loss: 0.3907 - val_categorical_accuracy: 0.8422\n",
            "\n",
            "Epoch 00010: saving model to weights\n",
            "Epoch 11/100\n",
            " - 6s - loss: 0.4662 - categorical_accuracy: 0.8110 - val_loss: 0.3916 - val_categorical_accuracy: 0.8413\n",
            "\n",
            "Epoch 00011: saving model to weights\n",
            "Epoch 12/100\n",
            " - 6s - loss: 0.4656 - categorical_accuracy: 0.8110 - val_loss: 0.3916 - val_categorical_accuracy: 0.8425\n",
            "\n",
            "Epoch 00012: saving model to weights\n",
            "Epoch 13/100\n",
            " - 6s - loss: 0.4650 - categorical_accuracy: 0.8113 - val_loss: 0.3906 - val_categorical_accuracy: 0.8433\n",
            "\n",
            "Epoch 00013: saving model to weights\n",
            "Epoch 14/100\n",
            " - 6s - loss: 0.4651 - categorical_accuracy: 0.8113 - val_loss: 0.3910 - val_categorical_accuracy: 0.8415\n",
            "\n",
            "Epoch 00014: saving model to weights\n",
            "Epoch 15/100\n",
            " - 6s - loss: 0.4655 - categorical_accuracy: 0.8110 - val_loss: 0.3910 - val_categorical_accuracy: 0.8429\n",
            "\n",
            "Epoch 00015: saving model to weights\n",
            "Epoch 16/100\n",
            " - 6s - loss: 0.4651 - categorical_accuracy: 0.8114 - val_loss: 0.3918 - val_categorical_accuracy: 0.8411\n",
            "\n",
            "Epoch 00016: saving model to weights\n",
            "Epoch 17/100\n",
            " - 6s - loss: 0.4655 - categorical_accuracy: 0.8112 - val_loss: 0.3908 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00017: saving model to weights\n",
            "Epoch 18/100\n",
            " - 6s - loss: 0.4651 - categorical_accuracy: 0.8115 - val_loss: 0.3906 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00018: saving model to weights\n",
            "Epoch 19/100\n",
            " - 6s - loss: 0.4648 - categorical_accuracy: 0.8112 - val_loss: 0.3919 - val_categorical_accuracy: 0.8408\n",
            "\n",
            "Epoch 00019: saving model to weights\n",
            "Epoch 20/100\n",
            " - 6s - loss: 0.4650 - categorical_accuracy: 0.8115 - val_loss: 0.3924 - val_categorical_accuracy: 0.8405\n",
            "\n",
            "Epoch 00020: saving model to weights\n",
            "Epoch 21/100\n",
            " - 6s - loss: 0.4654 - categorical_accuracy: 0.8109 - val_loss: 0.3908 - val_categorical_accuracy: 0.8416\n",
            "\n",
            "Epoch 00021: saving model to weights\n",
            "Epoch 22/100\n",
            " - 6s - loss: 0.4655 - categorical_accuracy: 0.8111 - val_loss: 0.3909 - val_categorical_accuracy: 0.8424\n",
            "\n",
            "Epoch 00022: saving model to weights\n",
            "Epoch 23/100\n",
            " - 6s - loss: 0.4653 - categorical_accuracy: 0.8110 - val_loss: 0.3907 - val_categorical_accuracy: 0.8423\n",
            "\n",
            "Epoch 00023: saving model to weights\n",
            "Epoch 24/100\n",
            " - 6s - loss: 0.4646 - categorical_accuracy: 0.8117 - val_loss: 0.3908 - val_categorical_accuracy: 0.8424\n",
            "\n",
            "Epoch 00024: saving model to weights\n",
            "Epoch 25/100\n",
            " - 6s - loss: 0.4646 - categorical_accuracy: 0.8114 - val_loss: 0.3922 - val_categorical_accuracy: 0.8399\n",
            "\n",
            "Epoch 00025: saving model to weights\n",
            "Epoch 26/100\n",
            " - 6s - loss: 0.4655 - categorical_accuracy: 0.8109 - val_loss: 0.3924 - val_categorical_accuracy: 0.8394\n",
            "\n",
            "Epoch 00026: saving model to weights\n",
            "Epoch 27/100\n",
            " - 6s - loss: 0.4652 - categorical_accuracy: 0.8110 - val_loss: 0.3909 - val_categorical_accuracy: 0.8422\n",
            "\n",
            "Epoch 00027: saving model to weights\n",
            "Epoch 28/100\n",
            " - 6s - loss: 0.4648 - categorical_accuracy: 0.8116 - val_loss: 0.3911 - val_categorical_accuracy: 0.8422\n",
            "\n",
            "Epoch 00028: saving model to weights\n",
            "Epoch 29/100\n",
            " - 6s - loss: 0.4649 - categorical_accuracy: 0.8109 - val_loss: 0.3909 - val_categorical_accuracy: 0.8425\n",
            "\n",
            "Epoch 00029: saving model to weights\n",
            "Epoch 30/100\n",
            " - 6s - loss: 0.4649 - categorical_accuracy: 0.8117 - val_loss: 0.3917 - val_categorical_accuracy: 0.8410\n",
            "\n",
            "Epoch 00030: saving model to weights\n",
            "Epoch 31/100\n",
            " - 6s - loss: 0.4651 - categorical_accuracy: 0.8108 - val_loss: 0.3915 - val_categorical_accuracy: 0.8412\n",
            "\n",
            "Epoch 00031: saving model to weights\n",
            "Epoch 32/100\n",
            " - 6s - loss: 0.4647 - categorical_accuracy: 0.8112 - val_loss: 0.3921 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00032: saving model to weights\n",
            "Epoch 33/100\n",
            " - 6s - loss: 0.4650 - categorical_accuracy: 0.8115 - val_loss: 0.3915 - val_categorical_accuracy: 0.8419\n",
            "\n",
            "Epoch 00033: saving model to weights\n",
            "Epoch 34/100\n",
            " - 6s - loss: 0.4648 - categorical_accuracy: 0.8114 - val_loss: 0.3910 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00034: saving model to weights\n",
            "Epoch 35/100\n",
            " - 6s - loss: 0.4647 - categorical_accuracy: 0.8115 - val_loss: 0.3907 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00035: saving model to weights\n",
            "Epoch 36/100\n",
            " - 6s - loss: 0.4648 - categorical_accuracy: 0.8112 - val_loss: 0.3905 - val_categorical_accuracy: 0.8429\n",
            "\n",
            "Epoch 00036: saving model to weights\n",
            "Epoch 37/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8113 - val_loss: 0.3904 - val_categorical_accuracy: 0.8430\n",
            "\n",
            "Epoch 00037: saving model to weights\n",
            "Epoch 38/100\n",
            " - 6s - loss: 0.4641 - categorical_accuracy: 0.8115 - val_loss: 0.3911 - val_categorical_accuracy: 0.8415\n",
            "\n",
            "Epoch 00038: saving model to weights\n",
            "Epoch 39/100\n",
            " - 6s - loss: 0.4644 - categorical_accuracy: 0.8112 - val_loss: 0.3913 - val_categorical_accuracy: 0.8413\n",
            "\n",
            "Epoch 00039: saving model to weights\n",
            "Epoch 40/100\n",
            " - 6s - loss: 0.4643 - categorical_accuracy: 0.8116 - val_loss: 0.3910 - val_categorical_accuracy: 0.8413\n",
            "\n",
            "Epoch 00040: saving model to weights\n",
            "Epoch 41/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8119 - val_loss: 0.3907 - val_categorical_accuracy: 0.8422\n",
            "\n",
            "Epoch 00041: saving model to weights\n",
            "Epoch 42/100\n",
            " - 6s - loss: 0.4646 - categorical_accuracy: 0.8112 - val_loss: 0.3904 - val_categorical_accuracy: 0.8434\n",
            "\n",
            "Epoch 00042: saving model to weights\n",
            "Epoch 43/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8111 - val_loss: 0.3907 - val_categorical_accuracy: 0.8424\n",
            "\n",
            "Epoch 00043: saving model to weights\n",
            "Epoch 44/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8117 - val_loss: 0.3913 - val_categorical_accuracy: 0.8414\n",
            "\n",
            "Epoch 00044: saving model to weights\n",
            "Epoch 45/100\n",
            " - 6s - loss: 0.4643 - categorical_accuracy: 0.8114 - val_loss: 0.3910 - val_categorical_accuracy: 0.8419\n",
            "\n",
            "Epoch 00045: saving model to weights\n",
            "Epoch 46/100\n",
            " - 6s - loss: 0.4641 - categorical_accuracy: 0.8115 - val_loss: 0.3912 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00046: saving model to weights\n",
            "Epoch 47/100\n",
            " - 6s - loss: 0.4643 - categorical_accuracy: 0.8113 - val_loss: 0.3908 - val_categorical_accuracy: 0.8416\n",
            "\n",
            "Epoch 00047: saving model to weights\n",
            "Epoch 48/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8117 - val_loss: 0.3907 - val_categorical_accuracy: 0.8426\n",
            "\n",
            "Epoch 00048: saving model to weights\n",
            "Epoch 49/100\n",
            " - 6s - loss: 0.4640 - categorical_accuracy: 0.8113 - val_loss: 0.3918 - val_categorical_accuracy: 0.8407\n",
            "\n",
            "Epoch 00049: saving model to weights\n",
            "Epoch 50/100\n",
            " - 6s - loss: 0.4651 - categorical_accuracy: 0.8114 - val_loss: 0.3914 - val_categorical_accuracy: 0.8407\n",
            "\n",
            "Epoch 00050: saving model to weights\n",
            "Epoch 51/100\n",
            " - 6s - loss: 0.4653 - categorical_accuracy: 0.8115 - val_loss: 0.3916 - val_categorical_accuracy: 0.8410\n",
            "\n",
            "Epoch 00051: saving model to weights\n",
            "Epoch 52/100\n",
            " - 6s - loss: 0.4644 - categorical_accuracy: 0.8116 - val_loss: 0.3906 - val_categorical_accuracy: 0.8413\n",
            "\n",
            "Epoch 00052: saving model to weights\n",
            "Epoch 53/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8114 - val_loss: 0.3910 - val_categorical_accuracy: 0.8428\n",
            "\n",
            "Epoch 00053: saving model to weights\n",
            "Epoch 54/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8117 - val_loss: 0.3911 - val_categorical_accuracy: 0.8420\n",
            "\n",
            "Epoch 00054: saving model to weights\n",
            "Epoch 55/100\n",
            " - 6s - loss: 0.4648 - categorical_accuracy: 0.8113 - val_loss: 0.3910 - val_categorical_accuracy: 0.8420\n",
            "\n",
            "Epoch 00055: saving model to weights\n",
            "Epoch 56/100\n",
            " - 6s - loss: 0.4646 - categorical_accuracy: 0.8114 - val_loss: 0.3909 - val_categorical_accuracy: 0.8426\n",
            "\n",
            "Epoch 00056: saving model to weights\n",
            "Epoch 57/100\n",
            " - 6s - loss: 0.4644 - categorical_accuracy: 0.8113 - val_loss: 0.3910 - val_categorical_accuracy: 0.8415\n",
            "\n",
            "Epoch 00057: saving model to weights\n",
            "Epoch 58/100\n",
            " - 6s - loss: 0.4647 - categorical_accuracy: 0.8113 - val_loss: 0.3906 - val_categorical_accuracy: 0.8419\n",
            "\n",
            "Epoch 00058: saving model to weights\n",
            "Epoch 59/100\n",
            " - 6s - loss: 0.4641 - categorical_accuracy: 0.8115 - val_loss: 0.3907 - val_categorical_accuracy: 0.8422\n",
            "\n",
            "Epoch 00059: saving model to weights\n",
            "Epoch 60/100\n",
            " - 6s - loss: 0.4641 - categorical_accuracy: 0.8115 - val_loss: 0.3904 - val_categorical_accuracy: 0.8427\n",
            "\n",
            "Epoch 00060: saving model to weights\n",
            "Epoch 61/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8116 - val_loss: 0.3911 - val_categorical_accuracy: 0.8420\n",
            "\n",
            "Epoch 00061: saving model to weights\n",
            "Epoch 62/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8116 - val_loss: 0.3917 - val_categorical_accuracy: 0.8406\n",
            "\n",
            "Epoch 00062: saving model to weights\n",
            "Epoch 63/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8115 - val_loss: 0.3910 - val_categorical_accuracy: 0.8420\n",
            "\n",
            "Epoch 00063: saving model to weights\n",
            "Epoch 64/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8116 - val_loss: 0.3913 - val_categorical_accuracy: 0.8410\n",
            "\n",
            "Epoch 00064: saving model to weights\n",
            "Epoch 65/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8115 - val_loss: 0.3914 - val_categorical_accuracy: 0.8411\n",
            "\n",
            "Epoch 00065: saving model to weights\n",
            "Epoch 66/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8115 - val_loss: 0.3916 - val_categorical_accuracy: 0.8406\n",
            "\n",
            "Epoch 00066: saving model to weights\n",
            "Epoch 67/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8114 - val_loss: 0.3914 - val_categorical_accuracy: 0.8422\n",
            "\n",
            "Epoch 00067: saving model to weights\n",
            "Epoch 68/100\n",
            " - 6s - loss: 0.4647 - categorical_accuracy: 0.8114 - val_loss: 0.3919 - val_categorical_accuracy: 0.8405\n",
            "\n",
            "Epoch 00068: saving model to weights\n",
            "Epoch 69/100\n",
            " - 6s - loss: 0.4647 - categorical_accuracy: 0.8116 - val_loss: 0.3908 - val_categorical_accuracy: 0.8419\n",
            "\n",
            "Epoch 00069: saving model to weights\n",
            "Epoch 70/100\n",
            " - 6s - loss: 0.4643 - categorical_accuracy: 0.8118 - val_loss: 0.3909 - val_categorical_accuracy: 0.8422\n",
            "\n",
            "Epoch 00070: saving model to weights\n",
            "Epoch 71/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8114 - val_loss: 0.3911 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00071: saving model to weights\n",
            "Epoch 72/100\n",
            " - 6s - loss: 0.4646 - categorical_accuracy: 0.8111 - val_loss: 0.3910 - val_categorical_accuracy: 0.8421\n",
            "\n",
            "Epoch 00072: saving model to weights\n",
            "Epoch 73/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8114 - val_loss: 0.3918 - val_categorical_accuracy: 0.8424\n",
            "\n",
            "Epoch 00073: saving model to weights\n",
            "Epoch 74/100\n",
            " - 6s - loss: 0.4643 - categorical_accuracy: 0.8111 - val_loss: 0.3905 - val_categorical_accuracy: 0.8415\n",
            "\n",
            "Epoch 00074: saving model to weights\n",
            "Epoch 75/100\n",
            " - 6s - loss: 0.4641 - categorical_accuracy: 0.8114 - val_loss: 0.3912 - val_categorical_accuracy: 0.8416\n",
            "\n",
            "Epoch 00075: saving model to weights\n",
            "Epoch 76/100\n",
            " - 6s - loss: 0.4644 - categorical_accuracy: 0.8112 - val_loss: 0.3906 - val_categorical_accuracy: 0.8427\n",
            "\n",
            "Epoch 00076: saving model to weights\n",
            "Epoch 77/100\n",
            " - 6s - loss: 0.4647 - categorical_accuracy: 0.8114 - val_loss: 0.3905 - val_categorical_accuracy: 0.8422\n",
            "\n",
            "Epoch 00077: saving model to weights\n",
            "Epoch 78/100\n",
            " - 6s - loss: 0.4650 - categorical_accuracy: 0.8112 - val_loss: 0.3912 - val_categorical_accuracy: 0.8419\n",
            "\n",
            "Epoch 00078: saving model to weights\n",
            "Epoch 79/100\n",
            " - 6s - loss: 0.4649 - categorical_accuracy: 0.8111 - val_loss: 0.3908 - val_categorical_accuracy: 0.8417\n",
            "\n",
            "Epoch 00079: saving model to weights\n",
            "Epoch 80/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8112 - val_loss: 0.3913 - val_categorical_accuracy: 0.8425\n",
            "\n",
            "Epoch 00080: saving model to weights\n",
            "Epoch 81/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8116 - val_loss: 0.3911 - val_categorical_accuracy: 0.8413\n",
            "\n",
            "Epoch 00081: saving model to weights\n",
            "Epoch 82/100\n",
            " - 6s - loss: 0.4642 - categorical_accuracy: 0.8116 - val_loss: 0.3914 - val_categorical_accuracy: 0.8417\n",
            "\n",
            "Epoch 00082: saving model to weights\n",
            "Epoch 83/100\n",
            " - 6s - loss: 0.4653 - categorical_accuracy: 0.8116 - val_loss: 0.3906 - val_categorical_accuracy: 0.8418\n",
            "\n",
            "Epoch 00083: saving model to weights\n",
            "Epoch 84/100\n",
            " - 6s - loss: 0.4653 - categorical_accuracy: 0.8114 - val_loss: 0.3907 - val_categorical_accuracy: 0.8420\n",
            "\n",
            "Epoch 00084: saving model to weights\n",
            "Epoch 85/100\n",
            " - 6s - loss: 0.4641 - categorical_accuracy: 0.8114 - val_loss: 0.3918 - val_categorical_accuracy: 0.8426\n",
            "\n",
            "Epoch 00085: saving model to weights\n",
            "Epoch 86/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8117 - val_loss: 0.3914 - val_categorical_accuracy: 0.8430\n",
            "\n",
            "Epoch 00086: saving model to weights\n",
            "Epoch 87/100\n",
            " - 6s - loss: 0.4652 - categorical_accuracy: 0.8113 - val_loss: 0.3907 - val_categorical_accuracy: 0.8416\n",
            "\n",
            "Epoch 00087: saving model to weights\n",
            "Epoch 88/100\n",
            " - 6s - loss: 0.4651 - categorical_accuracy: 0.8116 - val_loss: 0.3908 - val_categorical_accuracy: 0.8416\n",
            "\n",
            "Epoch 00088: saving model to weights\n",
            "Epoch 89/100\n",
            " - 6s - loss: 0.4650 - categorical_accuracy: 0.8116 - val_loss: 0.3912 - val_categorical_accuracy: 0.8417\n",
            "\n",
            "Epoch 00089: saving model to weights\n",
            "Epoch 90/100\n",
            " - 6s - loss: 0.4659 - categorical_accuracy: 0.8110 - val_loss: 0.3914 - val_categorical_accuracy: 0.8431\n",
            "\n",
            "Epoch 00090: saving model to weights\n",
            "Epoch 91/100\n",
            " - 6s - loss: 0.4657 - categorical_accuracy: 0.8109 - val_loss: 0.3910 - val_categorical_accuracy: 0.8417\n",
            "\n",
            "Epoch 00091: saving model to weights\n",
            "Epoch 92/100\n",
            " - 6s - loss: 0.4647 - categorical_accuracy: 0.8112 - val_loss: 0.3929 - val_categorical_accuracy: 0.8398\n",
            "\n",
            "Epoch 00092: saving model to weights\n",
            "Epoch 93/100\n",
            " - 6s - loss: 0.4648 - categorical_accuracy: 0.8109 - val_loss: 0.3918 - val_categorical_accuracy: 0.8401\n",
            "\n",
            "Epoch 00093: saving model to weights\n",
            "Epoch 94/100\n",
            " - 6s - loss: 0.4653 - categorical_accuracy: 0.8109 - val_loss: 0.3911 - val_categorical_accuracy: 0.8421\n",
            "\n",
            "Epoch 00094: saving model to weights\n",
            "Epoch 95/100\n",
            " - 6s - loss: 0.4648 - categorical_accuracy: 0.8112 - val_loss: 0.3907 - val_categorical_accuracy: 0.8424\n",
            "\n",
            "Epoch 00095: saving model to weights\n",
            "Epoch 96/100\n",
            " - 6s - loss: 0.4648 - categorical_accuracy: 0.8119 - val_loss: 0.3913 - val_categorical_accuracy: 0.8428\n",
            "\n",
            "Epoch 00096: saving model to weights\n",
            "Epoch 97/100\n",
            " - 6s - loss: 0.4645 - categorical_accuracy: 0.8117 - val_loss: 0.3916 - val_categorical_accuracy: 0.8432\n",
            "\n",
            "Epoch 00097: saving model to weights\n",
            "Epoch 98/100\n",
            " - 6s - loss: 0.4644 - categorical_accuracy: 0.8116 - val_loss: 0.3905 - val_categorical_accuracy: 0.8427\n",
            "\n",
            "Epoch 00098: saving model to weights\n",
            "Epoch 99/100\n",
            " - 6s - loss: 0.4644 - categorical_accuracy: 0.8113 - val_loss: 0.3908 - val_categorical_accuracy: 0.8420\n",
            "\n",
            "Epoch 00099: saving model to weights\n",
            "Epoch 100/100\n",
            " - 6s - loss: 0.4641 - categorical_accuracy: 0.8115 - val_loss: 0.3912 - val_categorical_accuracy: 0.8413\n",
            "\n",
            "Epoch 00100: saving model to weights\n",
            "evaluate the model - train_set:\n",
            "Model: \"model_3\"\n",
            "_________________________________________________________________\n",
            "Layer (type)                 Output Shape              Param #   \n",
            "=================================================================\n",
            "input_3 (InputLayer)         (None, 100, 2)            0         \n",
            "_________________________________________________________________\n",
            "dense_7 (Dense)              (None, 100, 1024)         3072      \n",
            "_________________________________________________________________\n",
            "dense_8 (Dense)              (None, 100, 500)          512500    \n",
            "_________________________________________________________________\n",
            "dense_9 (Dense)              (None, 100, 4)            2004      \n",
            "=================================================================\n",
            "Total params: 517,576\n",
            "Trainable params: 517,576\n",
            "Non-trainable params: 0\n",
            "_________________________________________________________________\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Yicfdn5uTfRJ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "yPredict = model.predict(xTrain)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "G0GZDj_fzdk6",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 50
        },
        "outputId": "e8577b7e-595d-42ed-f0eb-63ba0eb99c32"
      },
      "source": [
        "print(\"保存QPSK解调模型 \\n\")\n",
        "    \n",
        "model.save('QPSKDemodulationModel.h5')"
      ],
      "execution_count": 70,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "保存QPSK解调模型 \n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gOl8WkRbTlSp",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "print(yPredict)\n",
        "print(yTrain)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "H4AVewtr-uJx",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# test model\n",
        "    LOW = -10\n",
        "    HIGH = 20\n",
        "    GAP = 2\n",
        "    NTest = 100\n",
        "    L=100\n",
        "    test_data_full = sio.loadmat('test_data_demodulation_psk4.mat')\n",
        "    test_data =test_data_full['test_data_demodulation_psk4']\n",
        "\n",
        "    test_data_real = test_data.real\n",
        "    test_data_imag = test_data.imag\n",
        "    #x_data_real = x_data_real.reshape((1000,100))\n",
        "    #x_data_imag = x_data_imag.reshape((1000,100))\n",
        "    test_data_re = np.stack((test_data_real, test_data_imag), axis=2)\n",
        "    yTest_full=sio.loadmat('test_label_demodulation_psk4.mat')\n",
        "    yTest= yTest_full['test_label_demodulation_psk4']\n",
        "    xTest = test_data_re[:,0:NTest]\n",
        "    #yTest = test_data[:,NTest]\n",
        "    #yTest.astype(int)\n",
        "    \n",
        "    yPredict = model.predict(xTest)\n",
        "    predict_curve = np.zeros((2, int((HIGH-LOW)/GAP) + 1)) # snr + Pc"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "h0oPRYT5qKjD",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "    #第一个for循环得到x轴的刻度\n",
        "    for i in range(predict_curve.shape[1]): # snr - [-10 -8 ... 18 20]\n",
        "        predict_curve[0, i] = LOW + GAP * i\n",
        "    #不同信噪比的信号 预测正确的个数\n",
        "    for i in range(test_data_re.shape[0]): \n",
        "        snr_loc = int((test_data_re[i, L,0] - LOW)/GAP);\n",
        "        for j in range(L):\n",
        "          if yTest[i,j] == np.argmax(yPredict[i,j]):\n",
        "            continue\n",
        "          else:\n",
        "            break\n",
        "        \n",
        "        if j == L-1 :\n",
        "          predict_curve[1, snr_loc] = predict_curve[1, snr_loc] + 1\n",
        "    #不同信噪比预测正确的百分比，结果应该为噪声越大，预测准确率越低，信噪比越高，预测准确率越高\n",
        "    for i in range(predict_curve.shape[1]): # Pc - cal pc(cnt_num/sum_num 390/100)\n",
        "        predict_curve[1, i] = predict_curve[1, i]/(NTest)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XYGXxMMVkyyi",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 151
        },
        "outputId": "aa1c7275-e98e-4d2e-dfe3-52a38e410565"
      },
      "source": [
        "print(np.argmax(yPredict[0,0]))\n",
        "print(yPredict.shape)\n",
        "print(yTest.shape)\n",
        "print(test_data_re[0,100])\n",
        "print(predict_curve)"
      ],
      "execution_count": 68,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "1\n",
            "(1600, 100, 4)\n",
            "(1600, 100)\n",
            "[-10.   0.]\n",
            "[[-10.    -8.    -6.    -4.    -2.     0.     2.     4.     6.     8.\n",
            "   10.    12.    14.    16.    18.    20.  ]\n",
            " [  0.     0.     0.     0.     0.     0.     0.     0.     0.     0.27\n",
            "    0.92   0.99   1.     1.     1.     1.  ]]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NcNrQyHZqNqe",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 295
        },
        "outputId": "cd5ba4dc-3f83-4b36-d4af-54846f4e1ae2"
      },
      "source": [
        "#输入测试集计算预测的准确性，可以看到snr 在10b之下的时候，由于噪声过大，模型解调正确率很低\n",
        "#当SNR大于等于10db的时候，模型接近百分之百预测正确信号的解调\n",
        "plt.plot(predict_curve[0], predict_curve[1], 'o-')\n",
        "\n",
        "plt.grid(True)\n",
        "#plt.legend(loc='lower right')\n",
        "plt.xlim((LOW, HIGH))\n",
        "plt.ylim((0,1))\n",
        "plt.xlabel('SNR(dB)')\n",
        "plt.ylabel('Pc')\n",
        "plt.title('QPSK Demodulation Prediction Accuracy')\n",
        "plt.savefig('QPSK_Demodulatio_accuracy.png', format='png')\n",
        "#res = np.vstack((snr, acc))"
      ],
      "execution_count": 69,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3deZhcZZn38e+vs0MSErJANgxLbIgEwiKI6NAgCrgAIiCM46CjMjPKvPqqODD6IoO7uF5eoJNRJrhiooBR0TACLYgoJIRFlkgHMOkOoUNIAp093ff7xzmdnHSqej9dXVW/z3X11VXnnHrO/ZxTVfdZnnoeRQRmZmYd1ZQ6ADMzG5ycIMzMrCAnCDMzK8gJwszMCnKCMDOzgpwgzMysICcIG5QkvUfSH/p72SKv/42kS3r7+lLoWGdJLZIO6UU575J0e/9GZ5XCC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dkeWSUdL6k+fVwnaWO67JOSvtKhvHMlXVVkXS3p/5mStqRlPCzpj5Jq03lzJM3Pq75mPeEEYVVL0knAW4FjI+Io4HR29xk1WdJZRV56T0TMJenj5q2STs7M+wRwfTdWvyLtMfRoko7T/gMgIh4Fpks6qOc1MutfThBWzaYAL0TENoCIeCEiVqfzrgU+2dmLI2IL8BBpx4OSXglsi4gX0ucHS7ovHSfis50UNRZYn3n+S7o3PrtZrpwgrJrdDsyQ9FdJ10s6JTPvPmC7pFOLvTjt7XMWu/tcOhl4MLPIN4FvR8Qcks7fsg5NLzGtAD4KZLtEWAK8vlc1MutHThBWtSKiBTgOuBRYC/xU0nsyi3wW+FSBl75e0sMkHQ4ujog16fQpaTntTgZ+kj7+QYcy2i8xHQp8BJiXmdcMTO15jcz6lxOEVbWIaI2I+oj4NHAZ8I7MvDuBUSSjcmXdk947eBXwPklz0+lbgJEdV9GNMBYB2e7BR6ZlmZWUE4RVLUm1kmZlJs0l6cQs67MkN573ko5g+EXg39NJTwCHZRa5l933Et7VSSivA1Zknr+SMu1J1CqLE4RVs9HAjeng7o+QjJd9dXaBdFzitQVe2+47wN+lI3fdDRyTdrcM8GGSwYMeZe8R9NrvQTwMfB54f2beqcCve1Ujs37k3lzN+pGkbwK/jIjf9fL1I4Dfk4xQt7NfgzPrIZ9BmPWvzwP79OH1BwFXODnYYOAzCDMzK8hnEGZmVpAThJmZFeQEYWZmBTlBmJlZQU4QZmZW0P8HQi2AGMA5mikAAAAASUVORK5CYII=\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oLBDgGXuTek6",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#8PSK数据读取\n",
        "seqLen = 100\n",
        "#8PSK 四个相位\n",
        "nClass = 8\n",
        "samNum = 1000 * nClass\n",
        "x_data_mat = sio.loadmat('train_demodulation_data_psk8.mat')\n",
        "x_data_complex = x_data_mat['signalData_psk8']\n",
        "x_data_real = x_data_complex.real\n",
        "x_data_imag = x_data_complex.imag\n",
        "#x_data_real = x_data_real.reshape((1000,100))\n",
        "#x_data_imag = x_data_imag.reshape((1000,100))\n",
        "x_train = np.stack((x_data_real, x_data_imag), axis=2)\n",
        "y_data_mat = sio.loadmat('train_demodulation_label_psk8.mat')\n",
        "y_data_mat_int  = y_data_mat['labelData_psk8']\n",
        "\n",
        "y_train = np_utils.to_categorical(y_data_mat_int, nClass)\n",
        "#分割训练集和验证集\n",
        "xTrain = x_train[0:int(x_train.shape[0]*9/10),:]\n",
        "yTrain = y_train[0:int(y_train.shape[0]*9/10),:]\n",
        "#此为验证集\n",
        "xVal = x_train[int(x_train.shape[0]*9/10):-1,:]\n",
        "yVal = y_train[int(y_train.shape[0]*9/10):-1,:]"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "RgF0RxcX5HWk",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "06e59cc9-67db-49fc-8648-7f1ea189180f"
      },
      "source": [
        "#8psk 模型训练及保存\n",
        " \n",
        "    # train model\n",
        "    _in_ = Input(shape = (xTrain.shape[1], xTrain.shape[2]))\n",
        "    ot = Dense(1024,activation='relu')(_in_)\n",
        "    #ot = Dense(256,use_bias=True, activation='relu')(ot)\n",
        "    ot = Dense(500,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(64,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(32,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(16,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(8,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(10,use_bias=True, activation='relu')(ot)\n",
        "    _out_ = Dense(nClass, activation='softmax')(ot)\n",
        "    model = Model(_in_, _out_)\n",
        "\n",
        "\n",
        "    #early_stopping = EarlyStopping(monitor='val_loss', patience=10)\n",
        "    checkpoint = ModelCheckpoint(filepath='weights', monitor='val_loss', verbose=1, save_best_only=False)\n",
        "    adam = optimizers.Adam(lr=0.01, beta_1=0.9, beta_2=0.999, epsilon=1e-08)\n",
        "    model.compile(loss='categorical_crossentropy',\n",
        "                   optimizer=adam,\n",
        "                   metrics=['categorical_accuracy'])\n",
        "\n",
        "\n",
        "    model.fit(xTrain, yTrain, \n",
        "              epochs=20, \n",
        "              batch_size=250,\n",
        "              validation_data=(xVal,yVal),\n",
        "              shuffle = True,\n",
        "              verbose = 2,\n",
        "              callbacks = [checkpoint])\n",
        "    print(\"evaluate the model - train_set:\")\n",
        "    model.summary()\n",
        "    print(\"保存8PSK解调模型 \\n\")\n",
        "    \n",
        "    model.save('8PSKDemodulationModel.h5')"
      ],
      "execution_count": 82,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Train on 900 samples, validate on 99 samples\n",
            "Epoch 1/20\n",
            " - 6s - loss: 1.4503 - categorical_accuracy: 0.4935 - val_loss: 1.2072 - val_categorical_accuracy: 0.5698\n",
            "\n",
            "Epoch 00001: saving model to weights\n",
            "Epoch 2/20\n",
            " - 6s - loss: 1.0604 - categorical_accuracy: 0.6262 - val_loss: 1.0167 - val_categorical_accuracy: 0.6174\n",
            "\n",
            "Epoch 00002: saving model to weights\n",
            "Epoch 3/20\n",
            " - 6s - loss: 0.9404 - categorical_accuracy: 0.6413 - val_loss: 0.9708 - val_categorical_accuracy: 0.6340\n",
            "\n",
            "Epoch 00003: saving model to weights\n",
            "Epoch 4/20\n",
            " - 6s - loss: 0.9305 - categorical_accuracy: 0.6496 - val_loss: 0.9449 - val_categorical_accuracy: 0.6406\n",
            "\n",
            "Epoch 00004: saving model to weights\n",
            "Epoch 5/20\n",
            " - 6s - loss: 0.8999 - categorical_accuracy: 0.6532 - val_loss: 0.9439 - val_categorical_accuracy: 0.6407\n",
            "\n",
            "Epoch 00005: saving model to weights\n",
            "Epoch 6/20\n",
            " - 6s - loss: 0.9047 - categorical_accuracy: 0.6544 - val_loss: 0.9345 - val_categorical_accuracy: 0.6389\n",
            "\n",
            "Epoch 00006: saving model to weights\n",
            "Epoch 7/20\n",
            " - 6s - loss: 0.8890 - categorical_accuracy: 0.6567 - val_loss: 0.9279 - val_categorical_accuracy: 0.6401\n",
            "\n",
            "Epoch 00007: saving model to weights\n",
            "Epoch 8/20\n",
            " - 6s - loss: 0.8895 - categorical_accuracy: 0.6557 - val_loss: 0.9242 - val_categorical_accuracy: 0.6427\n",
            "\n",
            "Epoch 00008: saving model to weights\n",
            "Epoch 9/20\n",
            " - 6s - loss: 0.8840 - categorical_accuracy: 0.6562 - val_loss: 0.9243 - val_categorical_accuracy: 0.6424\n",
            "\n",
            "Epoch 00009: saving model to weights\n",
            "Epoch 10/20\n",
            " - 6s - loss: 0.8842 - categorical_accuracy: 0.6564 - val_loss: 0.9235 - val_categorical_accuracy: 0.6421\n",
            "\n",
            "Epoch 00010: saving model to weights\n",
            "Epoch 11/20\n",
            " - 10s - loss: 0.8817 - categorical_accuracy: 0.6568 - val_loss: 0.9191 - val_categorical_accuracy: 0.6430\n",
            "\n",
            "Epoch 00011: saving model to weights\n",
            "Epoch 12/20\n",
            " - 6s - loss: 0.8812 - categorical_accuracy: 0.6571 - val_loss: 0.9197 - val_categorical_accuracy: 0.6419\n",
            "\n",
            "Epoch 00012: saving model to weights\n",
            "Epoch 13/20\n",
            " - 6s - loss: 0.8806 - categorical_accuracy: 0.6571 - val_loss: 0.9192 - val_categorical_accuracy: 0.6431\n",
            "\n",
            "Epoch 00013: saving model to weights\n",
            "Epoch 14/20\n",
            " - 6s - loss: 0.8796 - categorical_accuracy: 0.6571 - val_loss: 0.9196 - val_categorical_accuracy: 0.6428\n",
            "\n",
            "Epoch 00014: saving model to weights\n",
            "Epoch 15/20\n",
            " - 6s - loss: 0.8793 - categorical_accuracy: 0.6572 - val_loss: 0.9182 - val_categorical_accuracy: 0.6419\n",
            "\n",
            "Epoch 00015: saving model to weights\n",
            "Epoch 16/20\n",
            " - 6s - loss: 0.8789 - categorical_accuracy: 0.6569 - val_loss: 0.9187 - val_categorical_accuracy: 0.6423\n",
            "\n",
            "Epoch 00016: saving model to weights\n",
            "Epoch 17/20\n",
            " - 6s - loss: 0.8791 - categorical_accuracy: 0.6573 - val_loss: 0.9184 - val_categorical_accuracy: 0.6422\n",
            "\n",
            "Epoch 00017: saving model to weights\n",
            "Epoch 18/20\n",
            " - 6s - loss: 0.8788 - categorical_accuracy: 0.6568 - val_loss: 0.9179 - val_categorical_accuracy: 0.6446\n",
            "\n",
            "Epoch 00018: saving model to weights\n",
            "Epoch 19/20\n",
            " - 6s - loss: 0.8783 - categorical_accuracy: 0.6572 - val_loss: 0.9178 - val_categorical_accuracy: 0.6420\n",
            "\n",
            "Epoch 00019: saving model to weights\n",
            "Epoch 20/20\n",
            " - 6s - loss: 0.8784 - categorical_accuracy: 0.6568 - val_loss: 0.9174 - val_categorical_accuracy: 0.6430\n",
            "\n",
            "Epoch 00020: saving model to weights\n",
            "evaluate the model - train_set:\n",
            "Model: \"model_8\"\n",
            "_________________________________________________________________\n",
            "Layer (type)                 Output Shape              Param #   \n",
            "=================================================================\n",
            "input_8 (InputLayer)         (None, 100, 2)            0         \n",
            "_________________________________________________________________\n",
            "dense_22 (Dense)             (None, 100, 1024)         3072      \n",
            "_________________________________________________________________\n",
            "dense_23 (Dense)             (None, 100, 500)          512500    \n",
            "_________________________________________________________________\n",
            "dense_24 (Dense)             (None, 100, 8)            4008      \n",
            "=================================================================\n",
            "Total params: 519,580\n",
            "Trainable params: 519,580\n",
            "Non-trainable params: 0\n",
            "_________________________________________________________________\n",
            "保存8PSK解调模型 \n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TmGfBu545Ojn",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 295
        },
        "outputId": "49dff265-7c19-407b-ee58-11ad97ff4354"
      },
      "source": [
        "#8PSK 测试解调 对于不同SNR信号的解调性能\n",
        "# test model\n",
        "    LOW = -10\n",
        "    HIGH = 20\n",
        "    GAP = 2\n",
        "    NTest = 100\n",
        "    L=100\n",
        "    test_data_full = sio.loadmat('test_data_demodulation_psk8.mat')\n",
        "    test_data =test_data_full['test_data_demodulation_psk8']\n",
        "\n",
        "    test_data_real = test_data.real\n",
        "    test_data_imag = test_data.imag\n",
        "    #x_data_real = x_data_real.reshape((1000,100))\n",
        "    #x_data_imag = x_data_imag.reshape((1000,100))\n",
        "    test_data_re = np.stack((test_data_real, test_data_imag), axis=2)\n",
        "    yTest_full=sio.loadmat('test_label_demodulation_psk8.mat')\n",
        "    yTest= yTest_full['test_label_demodulation_psk8']\n",
        "    xTest = test_data_re[:,0:NTest]\n",
        "    #yTest = test_data[:,NTest]\n",
        "    #yTest.astype(int)\n",
        "    \n",
        "    yPredict = model.predict(xTest)\n",
        "    predict_curve = np.zeros((2, int((HIGH-LOW)/GAP) + 1)) # snr + Pc\n",
        "\n",
        "     #第一个for循环得到x轴的刻度\n",
        "    for i in range(predict_curve.shape[1]): # snr - [-10 -8 ... 18 20]\n",
        "        predict_curve[0, i] = LOW + GAP * i\n",
        "    #不同信噪比的信号 预测正确的个数\n",
        "    for i in range(test_data_re.shape[0]): \n",
        "        snr_loc = int((test_data_re[i, L,0] - LOW)/GAP);\n",
        "        for j in range(L):\n",
        "          if yTest[i,j] == np.argmax(yPredict[i,j]):\n",
        "            continue\n",
        "          else:\n",
        "            break\n",
        "        \n",
        "        if j == L-1 :\n",
        "          predict_curve[1, snr_loc] = predict_curve[1, snr_loc] + 1\n",
        "    #不同信噪比预测正确的百分比，结果应该为噪声越大，预测准确率越低，信噪比越高，预测准确率越高\n",
        "    for i in range(predict_curve.shape[1]): \n",
        "        predict_curve[1, i] = predict_curve[1, i]/(NTest)\n",
        "    \n",
        "    #输入测试集计算预测的准确性，可以看到snr 在10b之下的时候，由于噪声过大，模型解调正确率很低\n",
        "    #当SNR大于等于10db的时候，模型接近百分之百预测正确信号的解调\n",
        "    plt.plot(predict_curve[0], predict_curve[1], 'o-')\n",
        "\n",
        "    plt.grid(True)\n",
        "    #plt.legend(loc='lower right')\n",
        "    plt.xlim((LOW, HIGH))\n",
        "    plt.ylim((0,1))\n",
        "    plt.xlabel('SNR(dB)')\n",
        "    plt.ylabel('Pc')\n",
        "    plt.title('8PSK Demodulation Prediction Accuracy')\n",
        "    plt.savefig('8PSK_Demodulation_accuracy.png', format='png')\n",
        "    #res = np.vstack((snr, acc))"
      ],
      "execution_count": 83,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3de3yedX3/8dcnhzY9pWlpC23aUg4lUE4t7UA8QHC4AiJUNxXUCc7ZuY2p06EgDvkpOifbRCdOu6mAQxE37K9OtPwUMtTBbNO7tFBaLKVJmrb0dN9p06ZNk3x+f1xX6EV659hcue7D+/l45JH7On++15Vcn/v7/V4Hc3dERER6Kkk6ABERyU1KECIikpUShIiIZKUEISIiWSlBiIhIVkoQIiKSlRKE5CQzczM7c7jnzbLse83s8aEsm6Romc3sm2b2t0NcT6uZnT680UmhUIIYYWY2x8weM7O0me00s6+bWVlkmof/tK1mttXMbosse72ZrTWz/Wa2x8yeMLPTwml3mdm/R+atNrONZvY1M7MscWw1szYzO2BmGTP7HzP7sJkV7N9EZP+WdY9z94fc/Q9i2FatmXWFx/GAmW0ysw8M93YA3P3D7v75AcRUZ2Z/2mPZ8e6+JY64IttMm9nouLYh8SnYk0EO+wawC5gOzAcuB/6ixzxV7j4euBG408yuCr8tPgh8ApgInAbcB3T23ICZnQo8Baxw949473dDvs3dJ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azBiQySahAiw+uLwNgTWH42cJuSg+QC1SBERCQr1SBERCQrJQgREclKCUJERLJSghARkayUIEREJKv/D9EtKcG/12zxAAAAAElFTkSuQmCC\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "I7R_s9Sg5XF3",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#16QAM数据读取 训练数据在20-44db snr之间\n",
        "nClass = 16\n",
        "samNum = 1000 * nClass\n",
        "x_data_mat = sio.loadmat('train_demodulation_data_qam16.mat')\n",
        "x_data_complex = x_data_mat['signalData_qam16']\n",
        "x_data_real = x_data_complex.real\n",
        "x_data_imag = x_data_complex.imag\n",
        "#x_data_real = x_data_real.reshape((1,1000,100))\n",
        "#x_data_imag = x_data_imag.reshape((1,1000,100))\n",
        "x_train = np.stack((x_data_real, x_data_imag),axis=2)\n",
        "y_data_mat = sio.loadmat('train_demodulation_label_qam16.mat')\n",
        "y_data_mat_int  = y_data_mat['labelData_qam16']\n",
        "#y_data_mat_int =y_data_mat_int.reshape((1,1000,100))\n",
        "y_train = np_utils.to_categorical(y_data_mat_int, nClass)\n",
        "#分割训练集和验证集\n",
        "xTrain = x_train[0:int(x_train.shape[0]*9/10),:]\n",
        "yTrain = y_train[0:int(y_train.shape[0]*9/10),:]\n",
        "#此为验证集\n",
        "xVal = x_train[int(x_train.shape[0]*9/10):-1,:]\n",
        "yVal = y_train[int(y_train.shape[0]*9/10):-1,:]"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "KdlBsICLRhv0",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "bcb50a0b-b887-422c-cf28-02d6c492c8f4"
      },
      "source": [
        "x_train.shape"
      ],
      "execution_count": 191,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(10000, 100, 2)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 191
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "G3OLiovs5oC3",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "323deeb6-1acf-421d-f6dd-b654462d3e9b"
      },
      "source": [
        "#16QAM 模型训练及保存\n",
        " # train model\n",
        "    _in_ = Input(shape = (xTrain.shape[1], xTrain.shape[2]))\n",
        "    #ot = LSTM(100, return_sequences=False)(_in_)\n",
        "    ot = Dense(256,use_bias=True, activation='relu')(_in_)\n",
        "    ot = Dense(64,use_bias=True, activation='relu')(ot)\n",
        "   # ot = Dense(64,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(32,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(16,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(8,use_bias=True, activation='relu')(ot)\n",
        "    #ot = Dense(10,use_bias=True, activation='relu')(ot)\n",
        "    _out_ = Dense(nClass, activation='softmax')(ot)\n",
        "    model = Model(_in_, _out_)\n",
        "\n",
        "\n",
        "    #early_stopping = EarlyStopping(monitor='val_loss', patience=10)\n",
        "    checkpoint = ModelCheckpoint(filepath='weights', monitor='val_loss', verbose=1, save_best_only=False)\n",
        "    adam = optimizers.Adam(lr=0.01, beta_1=0.9, beta_2=0.999, epsilon=1e-08)\n",
        "    model.compile(loss='categorical_crossentropy',\n",
        "                   optimizer=adam,\n",
        "                   metrics=['categorical_accuracy'])\n",
        "\n",
        "\n",
        "    model.fit(xTrain, yTrain, \n",
        "              epochs=50, \n",
        "              batch_size=250,\n",
        "              validation_data=(xVal,yVal),\n",
        "              shuffle = True,\n",
        "              verbose = 2,\n",
        "              callbacks = [checkpoint])\n",
        "    print(\"evaluate the model - train_set:\")\n",
        "    model.summary()\n",
        "    print(\"保存16QAM解调模型 \\n\")\n",
        "    \n",
        "    model.save('16QAMDemodulationModel.h5')"
      ],
      "execution_count": 199,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Train on 9000 samples, validate on 999 samples\n",
            "Epoch 1/50\n",
            " - 4s - loss: 1.5270 - categorical_accuracy: 0.6840 - val_loss: 0.5462 - val_categorical_accuracy: 0.8182\n",
            "\n",
            "Epoch 00001: saving model to weights\n",
            "Epoch 2/50\n",
            " - 4s - loss: 0.4159 - categorical_accuracy: 0.8213 - val_loss: 0.3326 - val_categorical_accuracy: 0.8274\n",
            "\n",
            "Epoch 00002: saving model to weights\n",
            "Epoch 3/50\n",
            " - 4s - loss: 0.3389 - categorical_accuracy: 0.8270 - val_loss: 0.3072 - val_categorical_accuracy: 0.8308\n",
            "\n",
            "Epoch 00003: saving model to weights\n",
            "Epoch 4/50\n",
            " - 4s - loss: 0.3067 - categorical_accuracy: 0.8283 - val_loss: 0.3017 - val_categorical_accuracy: 0.8337\n",
            "\n",
            "Epoch 00004: saving model to weights\n",
            "Epoch 5/50\n",
            " - 4s - loss: 0.3259 - categorical_accuracy: 0.8257 - val_loss: 0.3662 - val_categorical_accuracy: 0.8307\n",
            "\n",
            "Epoch 00005: saving model to weights\n",
            "Epoch 6/50\n",
            " - 4s - loss: 0.3118 - categorical_accuracy: 0.8269 - val_loss: 0.2949 - val_categorical_accuracy: 0.8312\n",
            "\n",
            "Epoch 00006: saving model to weights\n",
            "Epoch 7/50\n",
            " - 4s - loss: 0.2930 - categorical_accuracy: 0.8276 - val_loss: 0.2892 - val_categorical_accuracy: 0.8305\n",
            "\n",
            "Epoch 00007: saving model to weights\n",
            "Epoch 8/50\n",
            " - 4s - loss: 0.3081 - categorical_accuracy: 0.8259 - val_loss: 0.3530 - val_categorical_accuracy: 0.8088\n",
            "\n",
            "Epoch 00008: saving model to weights\n",
            "Epoch 9/50\n",
            " - 5s - loss: 0.3304 - categorical_accuracy: 0.8234 - val_loss: 0.2946 - val_categorical_accuracy: 0.8309\n",
            "\n",
            "Epoch 00009: saving model to weights\n",
            "Epoch 10/50\n",
            " - 7s - loss: 0.2814 - categorical_accuracy: 0.8287 - val_loss: 0.2750 - val_categorical_accuracy: 0.8292\n",
            "\n",
            "Epoch 00010: saving model to weights\n",
            "Epoch 11/50\n",
            " - 5s - loss: 0.2693 - categorical_accuracy: 0.8291 - val_loss: 0.2670 - val_categorical_accuracy: 0.8323\n",
            "\n",
            "Epoch 00011: saving model to weights\n",
            "Epoch 12/50\n",
            " - 4s - loss: 0.2720 - categorical_accuracy: 0.8286 - val_loss: 0.2711 - val_categorical_accuracy: 0.8310\n",
            "\n",
            "Epoch 00012: saving model to weights\n",
            "Epoch 13/50\n",
            " - 4s - loss: 0.2671 - categorical_accuracy: 0.8291 - val_loss: 0.2678 - val_categorical_accuracy: 0.8308\n",
            "\n",
            "Epoch 00013: saving model to weights\n",
            "Epoch 14/50\n",
            " - 4s - loss: 0.2934 - categorical_accuracy: 0.8266 - val_loss: 0.2696 - val_categorical_accuracy: 0.8333\n",
            "\n",
            "Epoch 00014: saving model to weights\n",
            "Epoch 15/50\n",
            " - 4s - loss: 0.2758 - categorical_accuracy: 0.8286 - val_loss: 0.2634 - val_categorical_accuracy: 0.8323\n",
            "\n",
            "Epoch 00015: saving model to weights\n",
            "Epoch 16/50\n",
            " - 4s - loss: 0.2774 - categorical_accuracy: 0.8276 - val_loss: 0.2744 - val_categorical_accuracy: 0.8304\n",
            "\n",
            "Epoch 00016: saving model to weights\n",
            "Epoch 17/50\n",
            " - 4s - loss: 0.2648 - categorical_accuracy: 0.8285 - val_loss: 0.2606 - val_categorical_accuracy: 0.8325\n",
            "\n",
            "Epoch 00017: saving model to weights\n",
            "Epoch 18/50\n",
            " - 4s - loss: 0.2625 - categorical_accuracy: 0.8291 - val_loss: 0.3570 - val_categorical_accuracy: 0.8286\n",
            "\n",
            "Epoch 00018: saving model to weights\n",
            "Epoch 19/50\n",
            " - 4s - loss: 0.2993 - categorical_accuracy: 0.8278 - val_loss: 0.2663 - val_categorical_accuracy: 0.8314\n",
            "\n",
            "Epoch 00019: saving model to weights\n",
            "Epoch 20/50\n",
            " - 4s - loss: 0.2631 - categorical_accuracy: 0.8294 - val_loss: 0.2623 - val_categorical_accuracy: 0.8314\n",
            "\n",
            "Epoch 00020: saving model to weights\n",
            "Epoch 21/50\n",
            " - 4s - loss: 0.2620 - categorical_accuracy: 0.8300 - val_loss: 0.2679 - val_categorical_accuracy: 0.8315\n",
            "\n",
            "Epoch 00021: saving model to weights\n",
            "Epoch 22/50\n",
            " - 4s - loss: 0.2626 - categorical_accuracy: 0.8291 - val_loss: 0.2672 - val_categorical_accuracy: 0.8303\n",
            "\n",
            "Epoch 00022: saving model to weights\n",
            "Epoch 23/50\n",
            " - 4s - loss: 0.2602 - categorical_accuracy: 0.8288 - val_loss: 0.2591 - val_categorical_accuracy: 0.8300\n",
            "\n",
            "Epoch 00023: saving model to weights\n",
            "Epoch 24/50\n",
            " - 4s - loss: 0.2579 - categorical_accuracy: 0.8287 - val_loss: 0.2616 - val_categorical_accuracy: 0.8296\n",
            "\n",
            "Epoch 00024: saving model to weights\n",
            "Epoch 25/50\n",
            " - 4s - loss: 0.2576 - categorical_accuracy: 0.8280 - val_loss: 0.2592 - val_categorical_accuracy: 0.8308\n",
            "\n",
            "Epoch 00025: saving model to weights\n",
            "Epoch 26/50\n",
            " - 4s - loss: 0.2567 - categorical_accuracy: 0.8295 - val_loss: 0.2572 - val_categorical_accuracy: 0.8273\n",
            "\n",
            "Epoch 00026: saving model to weights\n",
            "Epoch 27/50\n",
            " - 4s - loss: 0.2577 - categorical_accuracy: 0.8284 - val_loss: 0.2573 - val_categorical_accuracy: 0.8276\n",
            "\n",
            "Epoch 00027: saving model to weights\n",
            "Epoch 28/50\n",
            " - 4s - loss: 0.2561 - categorical_accuracy: 0.8283 - val_loss: 0.2555 - val_categorical_accuracy: 0.8294\n",
            "\n",
            "Epoch 00028: saving model to weights\n",
            "Epoch 29/50\n",
            " - 4s - loss: 0.2560 - categorical_accuracy: 0.8282 - val_loss: 0.2560 - val_categorical_accuracy: 0.8296\n",
            "\n",
            "Epoch 00029: saving model to weights\n",
            "Epoch 30/50\n",
            " - 4s - loss: 0.2554 - categorical_accuracy: 0.8285 - val_loss: 0.2562 - val_categorical_accuracy: 0.8248\n",
            "\n",
            "Epoch 00030: saving model to weights\n",
            "Epoch 31/50\n",
            " - 4s - loss: 0.2561 - categorical_accuracy: 0.8272 - val_loss: 0.2575 - val_categorical_accuracy: 0.8309\n",
            "\n",
            "Epoch 00031: saving model to weights\n",
            "Epoch 32/50\n",
            " - 4s - loss: 0.2559 - categorical_accuracy: 0.8283 - val_loss: 0.2622 - val_categorical_accuracy: 0.8281\n",
            "\n",
            "Epoch 00032: saving model to weights\n",
            "Epoch 33/50\n",
            " - 4s - loss: 0.2620 - categorical_accuracy: 0.8284 - val_loss: 0.2600 - val_categorical_accuracy: 0.8299\n",
            "\n",
            "Epoch 00033: saving model to weights\n",
            "Epoch 34/50\n",
            " - 4s - loss: 0.2570 - categorical_accuracy: 0.8299 - val_loss: 0.2573 - val_categorical_accuracy: 0.8271\n",
            "\n",
            "Epoch 00034: saving model to weights\n",
            "Epoch 35/50\n",
            " - 4s - loss: 0.2541 - categorical_accuracy: 0.8296 - val_loss: 0.2551 - val_categorical_accuracy: 0.8246\n",
            "\n",
            "Epoch 00035: saving model to weights\n",
            "Epoch 36/50\n",
            " - 4s - loss: 0.2544 - categorical_accuracy: 0.8295 - val_loss: 0.2554 - val_categorical_accuracy: 0.8299\n",
            "\n",
            "Epoch 00036: saving model to weights\n",
            "Epoch 37/50\n",
            " - 4s - loss: 0.2544 - categorical_accuracy: 0.8284 - val_loss: 0.2589 - val_categorical_accuracy: 0.8261\n",
            "\n",
            "Epoch 00037: saving model to weights\n",
            "Epoch 38/50\n",
            " - 4s - loss: 0.2546 - categorical_accuracy: 0.8290 - val_loss: 0.2576 - val_categorical_accuracy: 0.8228\n",
            "\n",
            "Epoch 00038: saving model to weights\n",
            "Epoch 39/50\n",
            " - 4s - loss: 0.2545 - categorical_accuracy: 0.8282 - val_loss: 0.2585 - val_categorical_accuracy: 0.8263\n",
            "\n",
            "Epoch 00039: saving model to weights\n",
            "Epoch 40/50\n",
            " - 4s - loss: 0.2523 - categorical_accuracy: 0.8283 - val_loss: 0.2542 - val_categorical_accuracy: 0.8279\n",
            "\n",
            "Epoch 00040: saving model to weights\n",
            "Epoch 41/50\n",
            " - 4s - loss: 0.2543 - categorical_accuracy: 0.8276 - val_loss: 0.2600 - val_categorical_accuracy: 0.8244\n",
            "\n",
            "Epoch 00041: saving model to weights\n",
            "Epoch 42/50\n",
            " - 4s - loss: 0.2539 - categorical_accuracy: 0.8279 - val_loss: 0.2540 - val_categorical_accuracy: 0.8223\n",
            "\n",
            "Epoch 00042: saving model to weights\n",
            "Epoch 43/50\n",
            " - 4s - loss: 0.2538 - categorical_accuracy: 0.8279 - val_loss: 0.2556 - val_categorical_accuracy: 0.8261\n",
            "\n",
            "Epoch 00043: saving model to weights\n",
            "Epoch 44/50\n",
            " - 4s - loss: 0.2522 - categorical_accuracy: 0.8284 - val_loss: 0.2532 - val_categorical_accuracy: 0.8272\n",
            "\n",
            "Epoch 00044: saving model to weights\n",
            "Epoch 45/50\n",
            " - 4s - loss: 0.2520 - categorical_accuracy: 0.8286 - val_loss: 0.2534 - val_categorical_accuracy: 0.8274\n",
            "\n",
            "Epoch 00045: saving model to weights\n",
            "Epoch 46/50\n",
            " - 4s - loss: 0.2539 - categorical_accuracy: 0.8288 - val_loss: 0.2580 - val_categorical_accuracy: 0.8247\n",
            "\n",
            "Epoch 00046: saving model to weights\n",
            "Epoch 47/50\n",
            " - 4s - loss: 0.2527 - categorical_accuracy: 0.8287 - val_loss: 0.2572 - val_categorical_accuracy: 0.8270\n",
            "\n",
            "Epoch 00047: saving model to weights\n",
            "Epoch 48/50\n",
            " - 4s - loss: 0.2528 - categorical_accuracy: 0.8283 - val_loss: 0.2540 - val_categorical_accuracy: 0.8249\n",
            "\n",
            "Epoch 00048: saving model to weights\n",
            "Epoch 49/50\n",
            " - 4s - loss: 0.2512 - categorical_accuracy: 0.8281 - val_loss: 0.2522 - val_categorical_accuracy: 0.8251\n",
            "\n",
            "Epoch 00049: saving model to weights\n",
            "Epoch 50/50\n",
            " - 4s - loss: 0.2534 - categorical_accuracy: 0.8292 - val_loss: 0.2563 - val_categorical_accuracy: 0.8281\n",
            "\n",
            "Epoch 00050: saving model to weights\n",
            "evaluate the model - train_set:\n",
            "Model: \"model_48\"\n",
            "_________________________________________________________________\n",
            "Layer (type)                 Output Shape              Param #   \n",
            "=================================================================\n",
            "input_68 (InputLayer)        (None, 100, 2)            0         \n",
            "_________________________________________________________________\n",
            "dense_126 (Dense)            (None, 100, 256)          768       \n",
            "_________________________________________________________________\n",
            "dense_127 (Dense)            (None, 100, 64)           16448     \n",
            "_________________________________________________________________\n",
            "dense_128 (Dense)            (None, 100, 16)           1040      \n",
            "=================================================================\n",
            "Total params: 18,256\n",
            "Trainable params: 18,256\n",
            "Non-trainable params: 0\n",
            "_________________________________________________________________\n",
            "保存16QAM解调模型 \n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Lh7cz3ms5r9w",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 295
        },
        "outputId": "8d2286c1-ca05-4d14-85bc-a59c570506fc"
      },
      "source": [
        "#16QAM 测试解调 对于不同SNR信号的解调性能\n",
        "\n",
        "# test model\n",
        "    LOW = 20\n",
        "    HIGH = 45\n",
        "    GAP = 2\n",
        "    NTest = 100\n",
        "    L=100\n",
        "    test_data_full = sio.loadmat('test_data_demodulation_qam16.mat')\n",
        "    test_data =test_data_full['test_data_demodulation_qam16']\n",
        "\n",
        "    test_data_real = test_data.real\n",
        "    test_data_imag = test_data.imag\n",
        "    #x_data_real = x_data_real.reshape((1000,100))\n",
        "    #x_data_imag = x_data_imag.reshape((1000,100))\n",
        "    test_data_re = np.stack((test_data_real, test_data_imag), axis=2)\n",
        "    yTest_full=sio.loadmat('test_label_demodulation_qam16.mat')\n",
        "    yTest= yTest_full['test_label_demodulation_qam16']\n",
        "    xTest = test_data_re[:,0:NTest]\n",
        "    #yTest = test_data[:,NTest]\n",
        "    #yTest.astype(int)\n",
        "    \n",
        "    yPredict = model.predict(xTest)\n",
        "    predict_curve = np.zeros((2, int((HIGH-LOW)/GAP) + 1)) # snr + Pc\n",
        "\n",
        "     #第一个for循环得到x轴的刻度\n",
        "    for i in range(predict_curve.shape[1]): # snr - [-10 -8 ... 18 20]\n",
        "        predict_curve[0, i] = LOW + GAP * i\n",
        "    #不同信噪比的信号 预测正确的个数\n",
        "    for i in range(test_data_re.shape[0]): # Pc - count num [ 100]\n",
        "        snr_loc = int((test_data_re[i, L,0] - LOW)/GAP);\n",
        "        for j in range(L):\n",
        "          if yTest[i,j] == np.argmax(yPredict[i,j]):\n",
        "            continue\n",
        "          else:\n",
        "            break\n",
        "        \n",
        "        if j == L-1 :\n",
        "          predict_curve[1, snr_loc] = predict_curve[1, snr_loc] + 1\n",
        "    #不同信噪比预测正确的百分比，结果应该为噪声越大，预测准确率越低，信噪比越高，预测准确率越高\n",
        "    for i in range(predict_curve.shape[1]): # Pc - cal pc(cnt_num/sum_num 90/100)\n",
        "        predict_curve[1, i] = predict_curve[1, i]/(NTest)\n",
        "    \n",
        "    #输入测试集计算预测的准确性，可以看到snr 在40b之下的时候，由于噪声过大，模型解调正确率很低\n",
        "    #当SNR大于等于40db的时候，模型接近百分之百预测正确信号的解调\n",
        "    plt.plot(predict_curve[0], predict_curve[1], 'o-')\n",
        "\n",
        "    plt.grid(True)\n",
        "    #plt.legend(loc='lower right')\n",
        "    plt.xlim((LOW, HIGH))\n",
        "    plt.ylim((0,1))\n",
        "    plt.xlabel('SNR(dB)')\n",
        "    plt.ylabel('Pc')\n",
        "    plt.title('16QAM Demodulation Prediction Accuracy')\n",
        "    plt.savefig('16QAM_Demodulatio_accuracy.png', format='png')\n",
        "    #res = np.vstack((snr, acc))"
      ],
      "execution_count": 205,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3de5xcdX3/8dcnm2w29839HhJI2CRcwy0iKKu1cpECImhAK/RHpfZXWltbFNQitdjSokX9KdXUC2g1KVqKqaDRAitIwXAnkt1ACCG32dyT3U02m+zu5/fHOZM9DLO3sGfOmZn38/HYx84553vmfM53z85nvt/vme+YuyMiIpJrUNIBiIhIOilBiIhIXkoQIiKSlxKEiIjkpQQhIiJ5KUGIiEheShBSdMzMzWzuQJfNs++HzeyXR7NvkqLnbGbfNLO/PcrnaTGzYwc2OikmShAxMbMbzOxpM2szs7vzbB9uZneZ2U4z22dmj+Zsf7uZPWxmzeH2FWY2P8/zzDGzTjP71zzb3My2m9ngyLoh4bpuPwBjZhvMrDU89l4z+18z+7iZlez1Ymazw/o6Ulfu/kN3f28Mx6oN/2YtYR2vNbM/GujjALj7x9397/sQU52Z/XHOviPdfX0ccUWOucfMhsZ1DHlrSvYfPgW2ArcB3+1m+1JgHLAg/P1X2Q1mdjbwS+CnwDRgDvAi8LiZzc55no8Ce4APdfOPtge4MLJ8YbiuN3/g7qOAY4DbgU8D3+nDftI3W919JDCaoG7/zcwW5haKJqxSEl7H7wAcuKTAxy7JOo2Fu+snxh+CJHF3zrr5QBMwupt9HgPuyrP+58D3IssGvAr8KbANuCKnvAOfA34cWfcT4LPBn77bmDcA78lZdxbQCZwYLg8FvgRsDI/9TWBYuK0W2Ax8CtgOZIDLgIuAl4HdwGcizz0U+ApBUt0aPh4a2X5j+Bxbgf8TntfccFsd8MeRstcCv8mpg2zZ9wHPhXW/Cbg1Um5jWLYl/Dk7z3O9HXgK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ru52DmfPnQc8Gq46B3g2UuSrwL+6+0kEkylGHRd2Mb0KfBKITiXzNPCOozojkQGkBCFlK/wuhdOB64EdwH+Y2bWRIrcBn8uz6zvM7AWCid9WuntjuH5q+DxZ5wDLwsc/yHmObBfTccBfAksj27YD0/p/RiIDSwlCylo4G26du38euAH4QGTbw8Awgm/xi3osHDs4Abgu8tWNrUBV7iH6EMYK4J2R5arwuUQSpQQhZcvMasxsXmTVqQSTP0bdRjDw/Cbu/hrBxJHZefXrgbmRIo/TNZbw4R5COZfgS4+yjqcMZmCV9FOCkHI2kmA21DVm9iKwELg1WiD8nu8defbN+ibwzvCb/h4FFoXTKUPwncB/ZmarefM3mWXHIF4A/gH448i2dwEPHNUZiQwgzeYqMoDM7KvAf7v7/xzl/kOBXwPnRr4qUyQRakGIDKx/AIa/hf1nATcpOUgaqAUhIiJ5qQUhIiJ5KUGIiEheShAiIpKXEoSIiOSlBCEiInn9f7Z1gpgSEfCXAAAAAElFTkSuQmCC\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "a6TG6hoEF83c",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 840
        },
        "outputId": "92e6c517-1b61-4af5-831a-690140554145"
      },
      "source": [
        "print(x_train)"
      ],
      "execution_count": 119,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[[[-0.78469112  3.30504487]\n",
            "  [ 2.10543131  1.64010157]\n",
            "  [-0.10723487 -3.75611233]\n",
            "  ...\n",
            "  [ 1.97239224 -1.13529212]\n",
            "  [ 0.96898336 -3.71376571]\n",
            "  [ 1.7100208  -1.96093634]]\n",
            "\n",
            " [[-0.3281212  -0.04062746]\n",
            "  [ 0.1517269  -0.66460293]\n",
            "  [ 1.81116373 -0.63644686]\n",
            "  ...\n",
            "  [-1.06477326 -0.49528597]\n",
            "  [ 0.29232022 -1.06652387]\n",
            "  [ 0.85649757  0.57136247]]\n",
            "\n",
            " [[-2.11997348 -3.28819688]\n",
            "  [-9.92095309 10.74121293]\n",
            "  [ 9.4691849   9.72386486]\n",
            "  ...\n",
            "  [-9.72980453 -3.12768631]\n",
            "  [-8.84500164 -9.1535299 ]\n",
            "  [-9.22173425 -9.30095281]]\n",
            "\n",
            " ...\n",
            "\n",
            " [[-1.21625313  0.14082867]\n",
            "  [-0.54479144  1.37080208]\n",
            "  [-0.39279498 -0.46099419]\n",
            "  ...\n",
            "  [-0.68401827 -0.75497834]\n",
            "  [-0.49528023  1.78914072]\n",
            "  [ 1.10006836 -0.02705995]]\n",
            "\n",
            " [[-0.63406134 -1.57182096]\n",
            "  [ 0.52914044  1.72065352]\n",
            "  [ 1.79790015  0.55030569]\n",
            "  ...\n",
            "  [ 1.07768867  1.17814454]\n",
            "  [ 1.20704467 -1.66416709]\n",
            "  [-1.21635811 -0.60501412]]\n",
            "\n",
            " [[ 1.45460185 -0.23497657]\n",
            "  [ 1.07947173 -0.6700062 ]\n",
            "  [-0.92885823  0.41546535]\n",
            "  ...\n",
            "  [ 0.82817828 -0.4709257 ]\n",
            "  [-0.9028564   0.15779428]\n",
            "  [ 0.04092924 -0.25458015]]]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Gc9qYrPeGBke",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}